package com.example.customapp.mycustomapp.Directory;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.customapp.mycustomapp.R;
import com.example.customapp.mycustomapp.base.BaseActivity;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

public class MyAutoListViewActivity extends BaseActivity {
    private ListView mlistview;
    private List<String> mList;
    private ImageView ivBack;
    @Override
    public void initWidget() {

    }

    @Override
    public void widgetClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_auto_list_view);
        initView();
    }

    private void initView() {
        mlistview = (ListView) findViewById(R.id.id_listview);
        ivBack= (ImageView) findViewById(R.id.iv_back);
        mList = new ArrayList<String>();
        for (int i = 0; i < 50; i++) {
            mList.add(i + "");
        }
        mlistview.setAdapter(new MyAdapter());
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public Object getItem(int arg0) {
            return mList.get(arg0);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(MyAutoListViewActivity.this).inflate(R.layout.list_item, parent, false);
                convertView.setTag(holder);
                //对于listview，注意添加这一行，即可在item上使用高度
                AutoUtils.autoSize(convertView);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            return convertView;
        }

    }

    class ViewHolder {

    }

}
